package com.situ.day14lianxi;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;

import org.junit.Test;

public class Demo {
	@Test
	public void test1() {
		Student student1 = new Student(1, "张三", Gender.male);
		Student student2 = new Student(2, "李四", Gender.male);
		if (student1.getGender() == student2.getGender()) {
			System.out.println("性别一样");
		} else {
			System.out.println("性别不同");
		}
	}

	@Test
	public void test2() {
		GenderTest genderTest = GenderTest.male;
		System.out.println(genderTest);
		System.out.println(genderTest.getValue());
	}

	@Test
	public void test3() {
		String regex = "[a-zA-Z0-9]+@[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+)+";
		String mail = "yiyongwei159@163.com";
		mail.matches(regex);
		if (mail.matches(regex)) {
			System.out.println("是邮箱");
		} else {
			System.out.println("不是邮箱");
		}
	}

	@Test
	public void test4() {
		String str = "Java Android PHP C#";
		String[] array = str.split(" ");
		for (String string : array) {
			System.out.println(string);
		}
	}

	@Test
	public void test5() {
		String str = "Java Android PHP C#";
		String[] array = str.split(" ");
		for (String string : array) {
			System.out.println(string);
		}
	}

	@Test
	public void test6() {
		String regex = "\\d+";
		String str = "dfghu2344dfhi5644ffdhfi44EHHE35fhdf1235df";
		String[] array = str.split(regex);
		for (String string : array) {
			System.out.println(string);
		}
	}

	@Test
	public void test7() {
		FileReader fileReader = null;
		try {
			fileReader = new FileReader("a.txt");
			int length = 0;
			char[] buffer = new char[10];
			while ((length = fileReader.read(buffer)) != -1) {
				System.out.println(length);
				System.out.println(Arrays.toString(buffer));
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (fileReader != null) {
				try {
					fileReader.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	@Test
	public void test8() {
		FileReader fileReader = null;
		FileWriter fileWriter = null;
		try {
			fileReader = new FileReader("a.txt");
			fileWriter = new FileWriter("a_back.txt");
			int length = 0;
			char[] buffer = new char[10];
			while ((length = fileReader.read(buffer)) != -1) {
				fileWriter.write(buffer, 0, length);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Test
	public void test9() {
		FileReader fileReader = null;
		try {
			fileReader = new FileReader("a.txt");
			int length = 0;
			char[] buffer = new char[10];
			while ((length = fileReader.read(buffer)) != -1) {
				System.out.println(length);
				System.out.println(Arrays.toString(buffer));
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	@Test
	public void test10() {
		FileReader fileReader = null;
		FileWriter fileWriter = null;
		try {
			fileReader = new FileReader("a.txt");
			fileWriter = new FileWriter("a_bobo.txt");
			int length = 0;
			char[] buffer = new char[10];
			while ((length = fileReader.read(buffer)) != -1) {
				System.out.println(length);
				fileWriter.write(buffer, 0, length);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (fileWriter != null) {
				try {
					fileWriter.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (fileReader != null) {
				try {
					fileReader.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
	@Test
	public void test11() {
		FileInputStream fileInputStream = null;
		FileOutputStream fileOutputStream = null;
		try {
			fileInputStream = new FileInputStream("tupianxin.jpg");
			fileOutputStream = new FileOutputStream("tupianla.jpg");
			int length = 0;
			byte[] buffer = new byte[1024];
			while ((length = fileInputStream.read(buffer)) != -1) {
				fileOutputStream.write(buffer, 0, length);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (fileOutputStream != null) {
				try {
					fileOutputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (fileInputStream != null) {
				try {
					fileInputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
	@Test
	public void test12() {
		Teacher teacher = new Teacher(1, "张三", 24);
		ObjectOutputStream objectOutputStream = null;
		FileOutputStream fileOutputStream = null;
		try {
			fileOutputStream = new FileOutputStream("teacherss");
			objectOutputStream = new ObjectOutputStream(fileOutputStream);
			objectOutputStream.writeObject(teacher);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			if (objectOutputStream != null) {
				try {
					objectOutputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (fileOutputStream != null) {
				try {
					fileOutputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
	@Test
	public void test13() {
		FileInputStream fileInputStream = null;
		ObjectInputStream objectInputStream = null;
		try {
			fileInputStream = new FileInputStream("teacherss");
			objectInputStream = new ObjectInputStream(fileInputStream);
			Object object = objectInputStream.readObject();
			Teacher teacher = (Teacher)object;
			System.out.println(teacher);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} finally {
			if (objectInputStream != null) {
				try {
					objectInputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (fileInputStream != null) {
				try {
					fileInputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
	@Test
	public void test14() {
		FileInputStream fileInputStream = null;
		ObjectInputStream objectInputStream = null;
		try {
			fileInputStream = new FileInputStream("teacherss");
			objectInputStream = new ObjectInputStream(fileInputStream);
			Object object = objectInputStream.readObject();
			Teacher teacher = (Teacher)object;
			System.out.println(teacher);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}finally {
			if (objectInputStream != null) {
				try {
					objectInputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (fileInputStream != null) {
				try {
					fileInputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
	@Test
	public void test15() {
		String regex = "[a-zA-Z0-9]+@[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+)+";
		String str = "1040565173@163.com";
		if (str.matches(regex)) {
			System.out.println("这是邮箱");
		}else {
			System.out.println("这不是邮箱");
		}
	}
	
	@Test
	public void test16() {
		String str = "Java Android PHP IOS";
		String regex = " ";
		String[] array = str.split(regex);
		for (String string : array) {
			System.out.println(string);
		}
	}
	@Test
	public void test17() {
		String str = "Java Android PHP IOS";
		String regex = " ";
		String[] array = str.split(regex);
		for (String string : array) {
			System.out.println(string);
		}
	}
	@Test
	public void test18() {
		String regex = "\\d+";
		String str = "dfghu2344dfhi5644ffdhfi44EHHE35fhdf1235df";
		String[] arrays = str.split(regex);
		for (String string : arrays) {
			System.out.println(string);
		}
	}
	@Test
	public void test19() {
		String regex = "\\d+";
		String str = "ehrifdi3456dfhdfhoDSf223dffhfd34hi";
		String result = str.replaceAll(regex, "#number#");
		System.out.println(result);
	}
	

}
